public class ThreadDemo9 {
    public static void main(String[] args) {
        Thread  thread = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){ //代替了!isQuit
                //Thread.currentThread()获取当前实例的作用!
                System.out.println("这是一个中断测试!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;//为了顺利让线程结束！
                }
            }
            System.out.println("线程结束!");
        });
        thread.start();

        try {
            Thread.sleep(3000);//运行3秒后线程将运行结束!
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("让线程结束!");
        thread.interrupt();//代替了isQuit = true;
    }
}
